<?php

declare(strict_types=1);

namespace app\common\model;

use addons\Target\facade\Target;

class TaskList extends Base
{

    protected $name = 'task_list';
    /**
     * 任务添加释放冻结注册积分
     */
    public static function taskAdd($param, $user, $sysm)
    {
        $asserts = Assets::where('uid',$user->id)->find();
        //print('<pre>');print_r($asserts);die;
        parent::startTrans();
        try {
            if ($asserts->frost_integral > 0) {
                $money = round(($sysm['reg_integral']*$user->integral),2);
                if(($asserts->frost_integral-$money)>=0){
                    $moneys = $money;
                }else{
                    $moneys = $asserts->frost_integral;
                }
                
                $data['uid'] = $user->id;
                parent::create($data);
                Target::Account()->basics($user->id, 'frost_integral', $moneys, '冻结释放', '-')
                    ->createBonus();
                Target::Account()->basics($user->id, 'reg_integral', $moneys, '冻结释放', '+')
                        ->createBonus();
            }
            parent::commit();
            return ['code' => 1, 'msg' => '观看完成'];
        } catch (\Exception $e) {
            parent::rollback();
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }
}
